import './index.scss'
import React from 'react'
import { useDispatch } from 'react-redux'

const ErrorPage = function (props) {
	const { code, message, img, reloadAction, btnTitle } = props
	const dispatch = useDispatch()
	// const showRefrash = code === -1
	const showRefrash = true

	const reload = () => {
		if (toString.call(reloadAction) === '[object String]') {
			dispatch({ type: reloadAction })
		}
		if (toString.call(reloadAction) === '[object Function]') {
			reloadAction()
		}
	}

	return (
		<div className="error-container">
			<img alt="" className="img" src={img} />
			<p className="error-info">{message}</p>
			{showRefrash && (
				<div className="btn" onClick={reload}>
					{btnTitle}
				</div>
			)}
		</div>
	)
}

export default ErrorPage
